#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <X11/Xlib.h>
extern volatile unsigned short int pot_val[];
void* X_ui(void* args){
    Display *display;
    Window main_window;
    XEvent event;
    char *pot1 = malloc(sizeof("Pot 1 is: ")+5*sizeof(char));
    char *pot2 = malloc(sizeof("Pot 2 is: ")+5*sizeof(char));
    if((display=XOpenDisplay(getenv("DISPLAY")))==NULL){
        printf("Error opening X display");
        pthread_exit(NULL);
    }
    main_window = XCreateSimpleWindow(display, RootWindow(display, DefaultScreen(display)), 0, 0, 90, 35, 1, BlackPixel( display, DefaultScreen(display) ), WhitePixel( display, DefaultScreen(display)));    
    XMapWindow(display, main_window);
    XMoveWindow(display, main_window, ((DefaultScreenOfDisplay(display)->width)/2)-45, ((DefaultScreenOfDisplay(display)->height)/2)-17);
    XStoreName(display, main_window, "ACPCS 0.1b");
    while(1){
        XClearWindow(display, main_window);
        XResizeWindow(display, main_window, 90, 35);
        sprintf(pot1, "Pot 1 is: %d", pot_val[0]);
        XDrawString(display, main_window, DefaultGC(display, DefaultScreen(display)), 5 , 15, pot1, strlen(pot1));
        sprintf(pot2, "Pot 2 is: %d", pot_val[1]);
        XDrawString(display, main_window, DefaultGC(display, DefaultScreen(display)), 5, 30, pot2, strlen(pot2));    
        XFlush(display);
        usleep(100);
    }
}
